<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>电影售票</title>
    <script src="http://47.106.66.89:8080/js/vue.min.js"></script>
    <script src="http://47.106.66.89:8080/js/axios.min.js"></script>
    <link href="http://47.106.66.89:8080/js/ele-2.15.7/theme-chalk/index.css" rel="stylesheet">
    <script src="http://47.106.66.89:8080/js/ele-2.15.7/index.js"></script>
    <script src="/sign/js/sign.js"></script>
    <script src="/js/ranking.js"></script>
    <script src="/js/top.js"></script>
<!--    https://www.yidepiao.com/ -->
</head>
<body>
<div id="app">
    <el-container>
        <top>
            <template #search>
                <el-input style="width: auto;" id="name" placeholder="请输入电影,影院,活动" v-model="where.name">
                    <el-button slot="append" icon="el-icon-search" @click="search(2)"></el-button>
                </el-input>
            </template>
        </top>
        <el-main>
            <div class="c900">
                <el-carousel height="300px">
                    <el-carousel-item v-for="item in still">
                        <a :href="`detail.html?id=${item.id}`"><img :src="item.img"></a>
                    </el-carousel-item>
                </el-carousel>
                <el-row :gutter="10">
                    <el-col :span="17">
                        <el-card>
                            <el-row :gutter="20" style="margin-bottom: 20px">
                                <el-col v-for="(movie, index) in movies.records" v-if="index <= 3" :span="6" class="hsc">
                                    <a :href="`detail.html?id=${movie.id}`">
                                        <img :src="movie.img" @error="handleImageError($event, movie.id)">
                                        <div class="price">
                                            <span>{{movie.price == '待定' ? '待定' : movie.price+'￥'}} &nbsp;<small>起</small></span>
                                            <el-button type="primary" size="mini">订购</el-button>
                                        </div>
                                    </a>
                                </el-col>
                            </el-row>
                            <el-row :gutter="20" style="margin-bottom: 20px">
                                <el-col v-for="(movie, index) in movies.records" v-if="index > 3" :span="6" class="hsc">
                                    <a :href="`detail.html?id=${movie.id}`">
                                        <img :src="movie.img" @error="handleImageError($event, movie.id)">
                                        <div class="price">
                                            <span>{{movie.price == '待定' ? '待定' : movie.price+'￥'}} &nbsp;<small>起</small></span>
                                            <el-button type="primary" size="mini">订购</el-button>
                                        </div>
                                    </a>
                                </el-col>
                            </el-row>
                            <div style="display: flex;justify-content: center;">
                                <el-pagination
                                        layout="prev, pager, next"
                                        :page-size="this.movies.size"
                                        :current-page="this.movies.current"
                                        @current-change="changeCurrent"
                                        :total="this.movies.total">
                                </el-pagination>
                            </div>
                        </el-card>
                    </el-col>
                    <el-col :span="7">
<!--                        热门排名组件-->
                        <ranking></ranking>
                    </el-col>
                </el-row>
            </div>
        </el-main>
        <el-footer class="flex title" style="justify-content: center;height: 30px">
            <a href="http://www.hyycinfo.com" target="_blank">源辰信息科技</a>
        </el-footer>
    </el-container>
</div>
</body>
<script>
    var v = new Vue({
        el:"#app",
        data:{
            where:{name:'',status:0},
            img:'https://tse1-mm.cn.bing.net/th/id/OIP-C.lCw8yzAgcesQi0fdACCG1wHaLM?w=198&h=299&c=7&r=0&o=5&pid=1.7',
            movies:{current:1,size:8,records:[]},
            still:[],
        },
        methods:{
            queryMovies(){
                axios.post(`movie/queryMovies?current=${this.movies.current}&size=${this.movies.size}`,this.where).then(res=>{
                    this.movies = res.data;
                    console.info(this.movies);
                });
            },
            changeCurrent(newPage){
                this.movies.current = newPage;
                this.queryMovies();
            },
            handleImageError(event, movieId) {
                // 可以在这里修改movie对象来标记图片加载失败，或者设置备用图片URL
                console.error(`Image failed to load for movie ID: ${movieId}`, event);
                // 假设你有一个备用图片URL
                event.target.src = this.img;
                event.target.style.width = '150.84px';
                event.target.style.height = '188.55px';
            },
            forget(){
                this.$refs.a.showForget = true;
            },
            //搜索
            search(num){
                if(num == 1){
                    //跳转查询
                    const urlParams = new URLSearchParams(window.location.search);
                    this.where.name = urlParams.get('name');
                }else if(num == 2){
                    this.movies.current = 1;
                }
                this.queryMovies();
            },
        },
        created(){
            this.queryMovies();
            //判断地址
            if(window.location.href.includes("index.html?name=")){
                //有参数
                this.search(1);
            }else{
                this.search(0);
            }
        }
    })
</script>
<style>
    html,body{
        margin: 0px;
        padding: 0px;
    }
    .el-main{
        padding: 10px 0px;
        overflow-x: hidden;
        background-image: url("https://img2.baidu.com/it/u=2454799735,2381918605&fm=253&fmt=auto&app=138&f=JPEG?w=750&h=500");
        background-size: cover;
    }
    .el-card{
        margin-top: 10px;
    }
    html,body,#app,#app>.el-container{
        height: 100%;
    }
    *{
        transition: all .5s;
    }
    a{
        text-decoration: none;
    }
    .c900{
        width: 1000px;
        margin: auto;
    }
    .title{
        background-color: #0a699999;
        color: #fff;
    }
    .title *{
        color: #fff;
    }
    .flex{
        display: flex;
        align-items: center;
        justify-content: space-between;
        height: 100%;
        gap: 10px;
    }
    .flex>*{
        margin: 0px;
        padding: 0px;
    }
    .center{
        display: flex;
        justify-content: center;
        align-items: center;
    }
    nav{
        display: flex;
        height: 100%;
    }
    nav .el-link{
        padding-inline: 20px;
        font-size: 1em;
    }
    nav .el-link:hover{
        background-color: #99f7;
    }
    img{
        width: 100%;
        object-fit: cover;
    }
    .hsc:hover{
        transform: scale(1.1);
        box-shadow: 3px 3px 3px 3px #8888;
    }
    .grid2{
        display: grid;
        grid-template-columns: auto auto;
    }
    .grid3{
        display: grid;
        grid-template-columns: auto auto auto;
    }
    .grid4{
        display: grid;
        grid-template-columns: auto auto auto auto;
    }
    .price{
        font-size: .8em;
        display: grid;
        grid-gap: 10px;
        grid-template-columns: 50% 50%;
        padding: 5px;
    }
    .price>span{
        display: flex;
        justify-content: start;
        align-items: center;
    }
    small{
        font-size: .4em;
    }
    .el-icon-search{
        color: #666;
    }
    #name{
        color: #444444;
    }
</style>

</html>